package bestfriends.tamu;

import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

import android.os.Environment;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;

public class ListManager {
	public static ArrayList<Person> people = new ArrayList<Person>();
	public static ArrayList<Question> questions = new ArrayList<Question>();
	
	
	public static void writeArraysToSD(){
		//need to write arrays to SD card DUH!
		//use xstream
		XStream xStream = new XStream(new DomDriver());
		
		String peopleXML = "";
		for(Person p : people) {
			peopleXML += xStream.toXML(p);
		}
		
		String questionsXML = "";
		for(Question q : questions) {
			questionsXML += xStream.toXML(q);
		}
		
		//get SD card
		File sdCard = Environment.getExternalStorageDirectory();
		
		File data = new File(sdCard,"data.xml");
		File questions = new File(sdCard,"questions.xml");
		try {
		FileOutputStream dataStream = new FileOutputStream(data);
		FileOutputStream questionStream = new FileOutputStream(questions);
		
		dataStream.write(peopleXML.getBytes());
		questionStream.write(questionsXML.getBytes());
		} catch(Exception e) {
			//could be FileNotFoundException from the stream
			//or IOException from the write
			e.printStackTrace();
		}
		
	}	
	
	
	
}
   